window.onload=function () {
    var app = new Vue({
        el: "#app",
        data: {
            pagination: {
                total: 0, //总记录数
                pageSize: 10, //每页的记录数
                pageNum: 1, //当前页码
            },
            answerlist:[],//所有回答
            myanswers:{
                answer_id:"",//回答id
                uname:"",//发布用户
                state:"",
                uid:0,
            },
            state:"",
            options:[{
                value:'1',
                label: '上架'},
                {
                    value:'2',
                    label: '下架'},
                {
                    value:'0',
                    label: '已删除'}
            ],
            lookmyanswers:false,//查看详情弹出框
            myupdateanswers:false
        },
        methods: {
            initmyanswerlist(){
                //初始化数据
                methodaxios.get(null,"/answer/answerlist?currentPage="+this.pagination.pageNum+"&pageSize="+this.pagination.pageSize+"&state="+this.state,rep=>{
                   window.console.log(rep.data.data)
                    this.answerlist=rep.data.data;
                    this.pagination.total=rep.data.count;
                });
            },//当前页发送改变
            findBlogPageList(page) {
                //页数改变
                this.pagination.pageNum = page;
                this.initmyanswerlist();
            }, //每页大小发送改变
            sizeChange(size) {
                this.pagination.pageSize = size; //当前页显示多少
                this.pagination.pageNum = 1;
                this.initmyanswerlist();
            },//点击搜索
            searchanswer(){
                //this.pagination.pageSize = size; //当前页显示多少
                this.pagination.pageNum = 1;
                this.initmyanswerlist();
            },
            resetanswers(){
                this.state=""
                // this.pagination.pageSize = size; //当前页显示多少
                this.pagination.pageNum = 1;
                this.initmyanswerlist();
            },
            lookanswer(row){//用户点击查看详情按钮
                var E = window.wangEditor
                var editor = new E('#editor')
                editor.create()
                this.lookmyanswers=true
                this.myanswers.uname=row.uname;
                editor.$textElem.attr('contenteditable', false)
                editor.txt.html('<p>' +row.answer_comment+'</p>' );
            },
            updatebutten(row){//点击修改按钮
                window.console.log(row)
                this.myanswers.answer_id=row.answer_id;
                this.myanswers.uname=row.uname;
                this.myanswers.state=row.state;
                this.myanswers.uid=row.uid;
                this.myupdateanswers=true
                var E = window.wangEditor
                var editor = new E('#updateeditoranswer')
                editor.create()
                editor.$textElem.attr('contenteditable', false)
                editor.txt.html('<p>' +row.answer_comment+'</p>' );
            },
            confirmupdates(){//确定修改
                if(isBlank(this.myanswers.state)){
                    layer.msg("请指定状态");
                    return false;
                }
                methodaxios.post("/answer/updateanswer",{
                    answer_id: this.myanswers.answer_id,
                    state: this.myanswers.state,
                    uid:this.myanswers.uid,
                },rep=>{
                    if(rep.data.code==="200"){
                        this.myanswers.answer_id=""
                        this.myanswers.state=""
                        layer.msg("修改成功");
                        this.myupdateanswers=false
                        this.initmyanswerlist();
                    }
                });
            }
        },mounted(){
            this.initmyanswerlist();
        },
        filters:{
            mytime(value){
                var dateee = new Date( value).toJSON();
                return new Date(+new Date(dateee) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')
            },
            mystate(value){
                if(value=="0"){
                    return "已删除"
                }else if(value=="1"){
                    return "上架"
                }else if(value=="2"){
                    return "下架"
                }
            }
        }

    })
}
